package com.probox.common.entity.service.customer.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.probox.common.core.enums.DataStatus;
import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.entity.domain.customer.LevelPrivileageGive;
import com.probox.common.entity.mapper.customer.LevelPrivileageGiveMapper;
import com.probox.common.entity.service.customer.ILevelPrivileageGiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 等级权益赠品关系映射Service业务层处理
 *
 * @author zsy
 * @date 2021-05-27
 */
@Service
@Transactional
public class LevelPrivileageGiveServiceImpl extends ServiceImpl<LevelPrivileageGiveMapper, LevelPrivileageGive> implements ILevelPrivileageGiveService {
    @Autowired
    private LevelPrivileageGiveMapper levelPrivileageGiveMapper;


    /**
     * 查询等级权益赠品关系映射
     *
     * @param giveId 等级权益赠品关系映射ID
     * @return 等级权益赠品关系映射
     */
    @Override
    public LevelPrivileageGive selectLevelPrivileageGiveById(Long giveId) {
        return this.getById(giveId);
    }

    /**
     * 查询等级权益赠品关系映射列表
     *
     * @param levelPrivileageGive 等级权益赠品关系映射
     * @return 等级权益赠品关系映射
     */
    @Override
    public List<LevelPrivileageGive> queryList(LevelPrivileageGive levelPrivileageGive) {
        QueryWrapper<LevelPrivileageGive> queryWrapper = Wrappers.query();
        return levelPrivileageGiveMapper.selectList(queryWrapper);
    }

    /**
     * 新增等级权益赠品关系映射
     *
     * @param levelPrivileageGive 等级权益赠品关系映射
     * @return 结果
     */
    @Override
    public boolean insertLevelPrivileageGive(LevelPrivileageGive levelPrivileageGive) {

        return this.save(levelPrivileageGive);

    }

    /**
     * 修改等级权益赠品关系映射
     *
     * @param levelPrivileageGive 等级权益赠品关系映射
     * @return 结果
     */
    @Override
    public boolean updateLevelPrivileageGive(LevelPrivileageGive levelPrivileageGive) {

        return this.updateById(levelPrivileageGive);
    }

    /**
     * 批量删除等级权益赠品关系映射
     *
     * @param giveIds 需要删除的等级权益赠品关系映射ID
     * @return 结果
     */
    @Override
    public boolean deleteLevelPrivileageGiveByIds(Long[] giveIds) {
        UpdateWrapper<LevelPrivileageGive> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("GIVE_ID", giveIds);
        updateWrapper.ne("status", DataStatus.delete.getKey());
        updateWrapper.set("status", DataStatus.delete.getKey());
        updateWrapper.set("UPDATE_USER", SecurityUtils.getUserId());
        updateWrapper.set("UPDATE_NAME", SecurityUtils.getUsername());
        updateWrapper.set("UPDATE_TIME", DateUtil.date());
        return this.update(updateWrapper);
    }

    /**
     * 根据权益id删除
     *
     * @param privileageId
     * @return
     */
    @Override
    public boolean deleteLevelPrivileageGiveByIds(Long privileageId) {
        UpdateWrapper<LevelPrivileageGive> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("privileage_Id", privileageId);
        updateWrapper.ne("status", DataStatus.delete.getKey());
        updateWrapper.set("status", DataStatus.delete.getKey());
        updateWrapper.set("UPDATE_USER", SecurityUtils.getUserId());
        updateWrapper.set("UPDATE_NAME", SecurityUtils.getUsername());
        updateWrapper.set("UPDATE_TIME", DateUtil.date());
        return this.update(updateWrapper);
    }

}
